# coding=utf-8
# !/usr/bin/python

import os
import configparser


class MyCnf(object):

    def __init__(self, config_filename=None):
        project_path = os.path.abspath(os.path.dirname(__file__))
        file_path = project_path[: len(project_path)-5] + config_filename
        self.cf = configparser.ConfigParser()
        self.cf.read(file_path)

    def __get_options(self, section):
        return self.cf.options(section)

    def get_value(self, section, option):
        value = self.cf.get(section, option)
        return int(value) if value.isdigit() else value

    def get_content(self, section):
        config = {}
        for option in self.__get_options(section):
            value = self.cf.get(section, option)
            config[option] = int(value) if value.isdigit() else value
        return config


if __name__ == '__main__':
    tmp_path = MyCnf('/cnf/my_config.cnf').get_value('bamboo', 'tmp_path')
    print(tmp_path)
    datasource = MyCnf('/cnf/my_config.cnf').get_content('datasource')
    print(datasource)
